//
//  OTDR_LocalPageViewController.m
//  OTDR
//
//  Created by Liu on 2024/6/18.
//

#import "OTDR_LocalPageViewController.h"
#import "OTDR_LocalDataViewController.h"
#import "OTDR_PDFFileViewController.h"
#import "OTDR_LocalDataCell.h"

@interface OTDR_LocalPageViewController ()<UITableViewDelegate,UITableViewDataSource>
/**
 *<#define#>
 */
@property(nonatomic ,strong)UITableView *tableView;
@end

@implementation OTDR_LocalPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavTitleStr:@""];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(0);
    }];
}

#pragma mark -- tableView
-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStyleGrouped];
        if (@available(iOS 15.0, *)) {
            _tableView.sectionHeaderTopPadding = 0;
        }
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate   = self;
        _tableView.dataSource = self;
        _tableView.estimatedRowHeight = 50;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        if (@available(iOS 11.0,*)) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
        }
        [_tableView registerClass:[OTDR_LocalDataCell class] forCellReuseIdentifier:@"OTDR_LocalDataCell"];
    }
    return _tableView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.001;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    OTDR_LocalDataCell  *cell = [tableView dequeueReusableCellWithIdentifier:@"OTDR_LocalDataCell" forIndexPath:indexPath];
    cell.fileName = indexPath.row == 0?@"📁 EIFlie":@"📁 PDFFile";
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated: NO];
    if (indexPath.row ==0 ) {
        OTDR_LocalDataViewController *vc = [OTDR_LocalDataViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else{
        OTDR_PDFFileViewController *vc = [OTDR_PDFFileViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
